package net.sansi.v3correctserver.entity.screen;

import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import net.sansi.v3correctserver.dto.v3serverapi.V3ServerApiScreenDto;

import java.util.List;

/**
 * Created by Fang
 * create time : 2024/11/4
 * IDE : IntelliJ IDEA
 * <p>
 * 显示屏
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class Screen extends Rect {
    @ApiModelProperty("显示屏 ID")
    private String id;

    @ApiModelProperty("显示屏名称")
    private String name;

    @ApiModelProperty("显示屏类型")
    private Integer type;

    @ApiModelProperty("显示屏型号")
    private String model;

    @ApiModelProperty("扫描板数量")
    private Integer scanBoardCount;

    @ApiModelProperty("扫描板宽度")
    private Integer scanBoardWidth;

    @ApiModelProperty("扫描板高度")
    private Integer scanBoardHeight;

    @ApiModelProperty("面板高度")
    private Integer panelHeight;

    @ApiModelProperty("面板宽度")
    private Integer panelWidth;

    @ApiModelProperty("校正系数")
    private Integer byteCount;

    @ApiModelProperty("校正系数固化模式")
    private String solidifyMode;

    @ApiModelProperty("发送盒校正系数预览支持")
    private boolean senderPreviewDisplayEnable;

    /**
     * 扫描板列表
     */
    @JsonIgnore
    private List<ScanBoard> scanBoards;

    /**
     * 获取所有灯点
     *
     * @return 所有灯点
     */
    @JsonIgnore
    public List<Panel> getPanels() {
        return scanBoards.stream().map(ScanBoard::getPanels).flatMap(List::stream).toList();
    }

    /**
     * 通过 v3-server api 响应数据创建 Screen 对象
     *
     * @param result v3-server api 响应数据
     * @return Screen 对象
     */
    public static Screen of(V3ServerApiScreenDto.ScreensResp.Result result) {
        Screen screen = new Screen();
        screen.setId(result.getId());
        screen.setName(result.getName());
        screen.setType(result.getType());
        screen.setModel(result.getModel());
        screen.setWidth(result.getScreenInfo().getScreenWidth());
        screen.setHeight(result.getScreenInfo().getScreenHeight());
        screen.setScanBoardCount(result.getScreenInfo().getScanBoardCount());
        screen.setScanBoardWidth(result.getScreenInfo().getScanBoardWidth());
        screen.setScanBoardHeight(result.getScreenInfo().getScanBoardHeight());
        screen.setByteCount(result.getScreenInfo().getCorrectDataParams().getByteCount());
        screen.setSolidifyMode(result.getScreenInfo().getCorrectDataParams().getSolidifyMode());
        screen.setSenderPreviewDisplayEnable(result.getScreenInfo().getSenderPreviewDisplayEnable());
        screen.setPanelWidth(result.getScreenInfo().getModuleWidth());
        screen.setPanelHeight(result.getScreenInfo().getModuleWidth());
        return screen;
    }

}
